package com.hoas.quickstart.threads.chapter05.chapter05_1_5;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Test8 {

    static class MyTask extends TimerTask {

        @Override
        public void run() {
            try {
                System.out.println("begin timer=" + System.currentTimeMillis());
                Thread.sleep(5000);
                System.out.println("end timer=" + System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }



    }

    public static void main(String[] args) {
        MyTask task = new MyTask();
        Calendar calendarRef = Calendar.getInstance();
        Date runDate = calendarRef.getTime();
        Timer timer = new Timer();
//        timer.schedule(task, runDate, 3000);
        timer.scheduleAtFixedRate(task, 3000, 2000);

    }

}
